package main

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	engine := gin.Default()

	// GET: http://localhost:8080/hello?name=davie
	engine.GET("/hello", func(context *gin.Context) {
		path := context.FullPath()
		fmt.Println(path)

		name := context.DefaultQuery("name", "hello")
		fmt.Println(name)

		context.String(http.StatusOK, "hello ,"+name)
	})

	// POST: http://localhost:8080/login
	engine.POST("/login", func(context *gin.Context) {
		path := context.FullPath()
		fmt.Println(path)

		username := context.PostForm("username")
		password := context.PostForm("password")
		mobile := context.PostForm("mobile")
		fmt.Println(password)
		fmt.Println(mobile)

		context.String(http.StatusOK, username+" 登录 ")
	})

	// Delete: http://localhost:8080/user/123
	engine.DELETE("/user/:id", func(context *gin.Context) {
		path := context.FullPath()
		fmt.Println(path)

		userID := context.Param("id")
		context.String(http.StatusOK, " 删除 用户ID: "+userID)
	})

	engine.Run()
}
